package com.fesine.learn.design.pattern.creational.simplefactory;

/**
 * @description: 类描述
 * @author: fesine
 * @createTime:2019/2/17
 * @update:修改内容
 * @author: fesine
 * @updateTime:2019/2/17
 */
public class VideoFactory {

    /**
     * 简单工厂方法，弊端无法进行扩展，否则违反开闭原则
     * @param type
     * @return
     */
    //public Video getVideo(String type){
    //    if("java".equalsIgnoreCase(type)){
    //        return new JavaVideo();
    //    }else if("python".equalsIgnoreCase(type)){
    //        return new PythonVideo();
    //    }
    //    return null;
    //}

    /**
     * 通过反射弥补简单工厂不足
     * 对比Calendar类和LoggerFactory类
     * @param c
     * @return
     */
    public Video getVideo(Class c){
        Video video = null;
        try {
            //通过类名获取实例
            video = (Video) Class.forName(c.getName()).newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return video;
    }


}
